package com.epic.followup.controller.app;

import com.epic.followup.service.app.AppPatientService;
import com.epic.followup.temporary.DealMessageResponse;
import com.epic.followup.temporary.app.patient.*;
import com.epic.followup.temporary.followup2.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author : zx
 * @version V1.0
 */

@Controller
@RequestMapping("/app/patient")
public class AppPatientController {

    @Autowired
    private AppPatientService appUserService;


    @RequestMapping(value = "/login/loginWithPasswd", method = RequestMethod.POST)
    @ResponseBody
    public DealMessageResponse loginWithPasswd(@RequestBody AppLoginbyPasswordRequest userInfo){

        return appUserService.loginbyPassword(userInfo);
    }

    @RequestMapping(value = "/login/loginWithIdentifyCode", method = RequestMethod.POST)
    @ResponseBody
    public AppLoginbyCodeResponse loginWithIdentifyCode(@RequestBody AppLoginbyCodeRequest userInfo){

        return appUserService.loginbyCode(userInfo);
    }

    @RequestMapping(value = "/register/registerWithPasswd", method = RequestMethod.POST)
    @ResponseBody
    public DealMessageResponse registerWithPasswd(@RequestBody AppRegisterRequest userInfo){
        return appUserService.register(userInfo);
    }

    @RequestMapping(value = "/getIdentifyCode", method = RequestMethod.POST)
    @ResponseBody
    public DealMessageResponse getCode(@RequestBody CodeRequest userInfo){
        if (userInfo.getType() == 0){//登录
            return appUserService.sendLoginCode(userInfo.getTel());
        }else if (userInfo.getType() == 1){//注册
            return appUserService.sendRegisterCode(userInfo.getTel());
        }else if (userInfo.getType() == 2){//重置密码
            return appUserService.sendResetPasswordCode(userInfo.getTel());
        }else {
            return null;
        }
    }

    @RequestMapping(value = "/register/modifyPasswd", method = RequestMethod.POST)
    @ResponseBody
    public DealMessageResponse resetPassword(@RequestBody AppRegisterRequest userInfo){
        return appUserService.resetPassword(userInfo);
    }

    @RequestMapping(value = "/user/userInfo", method = RequestMethod.POST)
    @ResponseBody
    public DealMessageResponse userInfo(@RequestBody AppInformationRequest userInfo){
        return appUserService.setInformation(userInfo);
    }



}
